<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['op']=='main'){
	$uniacid=$_RQ['uniacid'];
	$isshop=$_RQ['isshop'];
	$params=array();	
	$links=array();
	if(!$isshop){
		$list=pdo_getall('core_account_group',$params,array('id','title'),'','id desc');
		$links['group']=array(
				'title'=>'服务套餐/场景套餐',
				'url'=>manage_url('core/home.group_store/list/',true)
		);
		foreach($list as $item){		
			$links['group']['apps'][]=array(
				'title'=>$item['title'],
				'url'=>manage_url('core/home.group_store/detail/id='.$item['id'],true)
			);
		}
		$list=pdo_getall('core_article_group',$params,array('id','title'),'','id desc');
		$links['news']=array(
				'title'=>'新闻动态',
				'url'=>manage_url('core/home.news/list/',true)
		);
		foreach($list as $item){		
			$links['news']['apps'][]=array(
				'title'=>$item['title'],
				'url'=>manage_url('core/home.news/detail/id='.$item['id'],true)
			);
		}
		$uniacids=pdo_getall('core_account_plugin_setting',array('uniacid >'=>0,'plugin'=>'jy_weishop','key'=>'shopset'),array('uniacid','data'));
		foreach($uniacids as $item){
			$setting=json_decode($item['data'],true);
			$links['shop'.$item['uniacid']]=array(
					'title'=>$setting['title']?:'站点商城'.$item['uniacid'],
					'url'=>custom_url('jy_weishop/index/',true,$item['uniacid']),
					'ssrurl'=>manage_url('core/ssr//isshop=1&uniacid='.$item['uniacid'],true)
			);
			$params=array('uniacid'=>$item['uniacid'],'merchid'=>0,'mid'=>0,'parentid'=>0);
			$pindex = max(1, intval($_RQ['page']));
			$psize = 10;
			$total='';
			$fields=array('id','uniacid','title','paixu');
			$list=pdo_getslice('jy_weishop_goods_group',$params,array($pindex,$psize),$total,$fields,'','paixu desc, id desc');
			foreach($list as $item){		
				$links['shop'.$item['uniacid']]['apps'][]=array(
					'title'=>$item['title'],
					'url'=>custom_url('jy_weishop/goods.index//pid='.$item['id'],true,$item['uniacid'])
				);
			}
		}
		$page=core_setting('site');
		$return['page']=$page;
		$return['links']=$links;
		$return['sharedata']=array(
			'title'=>$page['title']?$page['title'].'-'.$_SERVER['HTTP_HOST']:'一站式小程序解决方案',
			'desc'=>$page['description']?$page['description']:'一个后台，全网发布，数据统一，体验统一',
			'link'=>manage_url('core/ssr//fromuser='.$_SESSION['uniacid'],true),
			'imgUrl'=>ATTACHMENT_URL.$page['logo']
		);
		$return['sharedata']['keywords']=$page['keywords']?:$return['sharedata']['desc'];
	}else{
		$shopset=pdo_get('core_account_plugin_setting',array('uniacid'=>$uniacid,'plugin'=>'jy_weishop','key'=>'shopset'),array('uniacid','data'));
		$shopset2=pdo_get('core_account_plugin_setting',array('uniacid'=>$uniacid,'plugin'=>'jy_weishop','key'=>'setting'),array('uniacid','data'));
		$setting=json_decode($shopset['data'],true);
		$setting2=json_decode($shopset2['data'],true);
		$links['news']=array(
			'title'=>$setting['title']?:'站点商城'.$item['uniacid'],
			'url'=>custom_url('jy_weishop/index/',true,$item['uniacid'])
		);
		$params=array('uniacid'=>$uniacid,'merchid'=>0,'mid'=>0,'parentid'=>0);
		$pindex = max(1, intval($_RQ['page']));
		$psize = 20;
		$total='';
		$fields=array('id','uniacid','title','isshow','paixu');
		$groups=pdo_getslice('jy_weishop_goods_group',$params,array($pindex,$psize),$total,$fields,'','paixu desc, id desc');
		foreach($groups as $item){		
				$links['news']['apps'][]=array(
					'title'=>$item['title'],
					'url'=>custom_url('jy_weishop/goods.index//pid='.$item['id'],true,$item['uniacid'])
				);
				$links['goods'.$item['id']]=array(
					'title'=>$item['title'].'-商品',
					'url'=>custom_url('jy_weishop/goods.index//pid='.$item['id'],true,$item['uniacid'])
				);
				$params=array('uniacid'=>$item['uniacid'],'pcate'=>$item['id'],'status'=>1,'type <>'=>4,'nochecked'=>0,'no_showsys'=>0,'merchid'=>0);
				$pindex = max(1, intval($_RQ['page']));
				$psize = 100;
				$total='';
				$fields=array('id','uniacid','title','status','paixu');
				$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','paixu desc, id desc');
				foreach($list as $gv){		
						$links['goods'.$item['id']]['apps'][]=array(
							'title'=>$gv['title'],
							'url'=>custom_url('jy_weishop/goods.detail//id='.$gv['id'],true,$item['uniacid'])
						);
				}
		}
		$return['links']=$links;
		$return['sharedata']=array(
			'title'=>$setting['title']?$setting['title'].'-'.$_SERVER['HTTP_HOST']:'商城系统',
			'desc'=>$setting2['share_desc']?$setting2['share_desc']:'商城系统',
			'link'=>manage_url('core/ssr//fromuser='.$_SESSION['uniacid'],true),
			'imgUrl'=>ATTACHMENT_URL.$setting['logo']
		);
		$return['sharedata']['keywords']=$setting2['share_keywords']?:$return['sharedata']['desc'];
	}
	$cloud=core_setting('cloud');
	$isauthgroup=$cloud['group']>=2?1:0;
	include cfc('template')->template('ssr/index');
}